import * as constants from './constants';
import { fromJS } from 'immutable';

const defaultState = fromJS({
    inputValue: '',
    list: [],
    todoList: [],
    index: 0,
    detail: {
        'Android': [],
        'App': [],
        'iOS': [],
        "休息视频": [],
        "拓展资源": [],
        "瞎推荐": [],
        "福利": []
    },
});

export default (state = defaultState, action) => {
    if (action.type === constants.CHANGE_INPUT_VALUE) {
        return state.set('inputValue', action.value);
    }

    if (action.type === constants.ADD_ITEM) {
        state.set('inputValue', '');
        return state.set('list', state.get('list').concat(state.get('inputValue'))).set('inputValue', '');
    }

    if (action.type === constants.DELETE_ITEM) {
        console.log(action.index);
        return state.set('list', state.get('list').splice(action.index, 1));
    }

    if (action.type === constants.INIT_LIST) {
        return state.set('todoList', action.data);
    }

    if (action.type === constants.GET_DETAIL) {
        // return state.set('detail', action.data);
        return state.set('detail', action.data);
    }

    return state;
}